# -*- coding: utf-8 -*-
"""
@Time ： 2025/4/12 11:39
@Auth ： Martina Luo
@Function ：字典，增删改查、合并（相加）
"""
dict1 = {}
dict1 = {1:1,'k2':2,'k3':'3'}

# 获取值
print(dict1[1])
print(len(dict1))

# 更新值
dict1['k2']= 'willam'
print(dict1)

# 删除
dict1.pop('k3')
print(dict1)

del dict1[1]
print(dict1)

dict1.clear()
print(dict1)

# 删除字典
del dict1

# 新增，和更新一样，键一样，值不一样，会被覆盖
dict2 = {}
dict2['k4']= 'willam'
print(dict2)

# 两个字典合并
dict1 = {1:1,'k2':2,'k3':'3'}
dict1.update(dict2)
print(dict1)

# 遍历
for key in dict1:
    print(key,end='\t')
print('',end='\n')
for value in dict1.values():
    print(value,end='\t')
print('',end='\n')
# 遍历字典 `dict1` 的所有键值对，并将每个键值对作为一个元组打印出来，每个元组后面用制表符（`\t`）分隔
for item in dict1.items():
    print(item,end='\t')
    # print(type(item))  # <class 'tuple'>
print('',end='\n')
for key,value in dict1.items():
    print(key,value,end='\t')
